package v3.chapter6.singleton_0;

public class Run {

	public static void main(String[] args) {
		MyThread t1 = new MyThread();
		MyThread t2 = new MyThread();
		MyThread t3 = new MyThread();
		
		t1.start();
		t2.start();
		t3.start();
	}

}

class MyThread extends Thread{
	@Override
	public void run() {
		System.out.println(MyObject.getInstance().hashCode());
	}
}

class MyObject{
	// 立即加载方式==饿汉模式
	private static MyObject myObject =new MyObject();
	
	private MyObject() {}
	
	public static MyObject getInstance() {
		//此代码版本为立即加载
		//此版本代码的缺点是不能有其它实例变量
		//因为getInstance()方法没有同步
		//所以有可能出现非线程安全问题
		return myObject;
	}
}